package cn.xz.gobang.dialog

import android.view.Gravity
import android.widget.TextView
import cn.xz.gobang.R
import cn.xz.gobang.base.BaseDialogRxFragment

/**
 * 获胜弹窗
 * */
class BackDialog: BaseDialogRxFragment() {

    private var mClickListener: OnClickListener? = null

    private var tvTitle: TextView? = null
    private var tvOver: TextView? = null
    private var tvCancel: TextView? = null


    companion object {
        fun newInstance(
            clickListener: OnClickListener
        ): BackDialog {
            val dialog = BackDialog()
            dialog.mClickListener = clickListener
            return dialog
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.item_back_dialog
    }

    override fun configDialog() {
        this.setDialogSize(gravity = Gravity.CENTER,width = 300)
    }

    override fun initViews() {

        dialog?.let {
            tvTitle = it.findViewById(R.id.tv_title)
            tvOver = it.findViewById(R.id.tv_over)
            tvCancel = it.findViewById(R.id.tv_cancel)
        }

        //点击外部不隐藏
        dialog?.setCancelable(false)
        dialog?.setCanceledOnTouchOutside(false)
        //视图相关
        initUI()
        //点击事件
        initEvent()
    }

    private fun initUI(){

    }

    private fun initEvent(){
        if (tvOver != null){
            tvOver?.setOnClickListener {
                mClickListener?.onYes()
                dismiss()
            }
        }
        if (tvCancel != null){
            tvCancel?.setOnClickListener {
                dismiss()
            }
        }
    }


    interface OnClickListener {
        fun onYes()
    }

}